package Threa;

import java.io.IOException;
import java.sql.SQLOutput;

public class Hospetal implements Runnable{
    @Override
    public void run() {
        for (int i=1;i<=10;i++){
            System.out.println(Thread.currentThread().getName()+":"+i+"号病病人在看病!");
//            if ( i==10){
//                try {
            try {
                Thread.sleep(500);//进入阻塞状态
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
        }
    }

    public static void main(String[] args) throws IOException {

        Hospetal my=new Hospetal();
        //特需病人
        Thread h1 = new Thread(my, "特需病人");
        h1.setPriority(Thread.MAX_PRIORITY);
        h1.start();
        for (int i=1;i<50;i++){
            if (i==10) {
                try {
                    h1.join();//进入让步
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
//            //普通病人
//            Thread h2=new Thread(my,"普通病人");
//            h2.setPriority(Thread.MIN_PRIORITY);//优先级
//            h2.start();
//            System.out.println(Thread.currentThread().getName()+":"+(i+1)+"号病人在看病!");
//            try{
//                Thread.sleep(500);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            System.out.println(Thread.currentThread().getName()+":"+(i+1)+"号病人在看病!");
        }
    }
}
